package countcharacter;

import java.util.HashSet;

public class Demo {
    public static void main(String[] args) {
        String str = "你好你好你好好abcdefg";
        HashSet<Character> seen = new HashSet<>();
        for (char c : str.toCharArray()) {
            if (!seen.contains(c)) {
                int count = countCharacter(str, c);
                System.out.println("字符 '" + c + "' 出现了 " + count + " 次");
                seen.add(c);
            }
        }
    }
    public static int countCharacter(String str,char c){
        int count = 0;
        for (char character : str.toCharArray()) {
            if(character==c){
                count++;
            }
        }
        return count;
    }
}
